<template>
  <div class="echart-index">
    <div id="main" style="width: 1200px;height:400px;"></div>
  </div>
</template>
<script>
import echarts from 'echarts'
import _ from 'lodash'
export default {
  name: 'EchartIndex',
  props: ['data'],
  data() {
    return {
      options: {
        // color:.
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#E9EEF3'
            }
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        series: [
          {
            itemStyle: {
              normal: {
                color: 'rgba(62,139,222,1)' // 线颜色
              }
            },
            areaStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {
                    // 折线图颜色渐变
                    offset: 0,
                    color: 'rgba(62,139,222,0.6)'
                  },
                  {
                    offset: 1,
                    color: 'rgba(62,139,222,0.01)'
                  }
                ])
              }
            }
          }
        ],

        yAxis: [
          {
            type: 'value',
            max: 200,
            axisLine: { show: false },
            axisTick: {
              show: true,
              lineStyle: {
                color: '#ccc'
              }
            }
          }
        ]
      }
    }
  },
  watch: {
    data: function(newvalue, old) {
      this.data = newvalue
      this.set()
    }
  },
  methods: {
    set() {
      var myChart = echarts.init(document.getElementById('main'))
      const result = _.merge(this.data, this.options)
      myChart.setOption(result)
    }
  },
  mounted() {
    this.set()
  }
}
</script>
<style lang="less" scoped>
.echart-index {
}
</style>
